package com.gw.quotes.net.service;

import org.ksoap2.serialization.SoapObject;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.gw.quotes.entity.business.ProjectListEntity;
import com.gw.quotes.entity.system.Result;
import com.gw.quotes.net.BaseServiceInter;
import com.gw.quotes.net.HttpCallBack;
import com.gw.quotes.net.NewException;
import com.gw.quotes.net.Request;
import com.gw.quotes.net.Response;

/**
 * 项目列表 getProjectlist
 * 
 * @author Administrator
 *
 */
public class ProjectListQueryServiceImpl extends WebBaseServiceImpl {

	@Override
	public Response setResponse() {
		return new Response();
	}
	@Override
	public void checkParam(Request request) throws NewException {
		if (request == null) {
			throw new NewException(Response.RESULT_ERROR, "传入request不能为空");
		}
		if (checkNull(request.getLoginname())) {
			throw new NewException(Response.RESULT_ERROR, "用户登录名不能为空");
		}
		if (checkNull(request.getTicket())) {
			throw new NewException(Response.RESULT_ERROR, "接口凭据不能为空");
		}
	}

	@Override
	public void setParamByRequest(Request request, SoapObject rpc)
			throws NewException {
		rpc.addProperty("arg0", request.getLoginname());
		rpc.addProperty("arg1", request.getTicket());
	}

	@Override
	public String getMethodName() throws NewException {
		return "getProjectlist";
	}

	@Override
	public void resolveResponse(Object object, Response response)
			throws NewException {
		Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss")
				.create();
		java.lang.reflect.Type type = new TypeToken<ProjectListEntity>() {
		}.getType();
		ProjectListEntity result = gson.fromJson(object.toString(), type);
		response.setMsg(result.getMsg());
		response.setResult(result.getResult());
		if (response.getResult() == Response.RESULT_SUCCESS) {
			response.setObj(result.getProjectlist());
			System.out.println(response.toString());
		}
		System.out.println("object" + object.toString());

	}
	
	String testStr="{  'result':1,  'projectlist':[{'endtime':'2014-05-23 16:09:48','buyerorgname':'杭州市上城区清波街道办事处本级','projectguid':'169494aa461a037801461dd900b74ee8','projectGoodList':[{ 'goodsname':'戴尔 DELL R420服务器 DELL R420服务器', 'projectguid':'169494aa461a037801461dd900b74ee8', 'projectoptionalList':[  {   'relativeprice':'-150',   'qty':'1',   'goodsoptionalname':'2*300G SAS 2.5寸 10K换1TB 7.2K RPM, 6Gbps 近线 SAS 2.5英寸 硬盘 - 热插拔',   'projectoptionalguid':'169494aa461a037801461dd900e64eec'  },  {   'relativeprice':'-850',   'qty':'1',   'goodsoptionalname':'2*300G SAS 2.5寸 10K换1TB 7.2K RPM 近线, 6Gbps SAS 3.5英寸热插拔硬盘',   'projectoptionalguid':'169494aa461a037801461dd900f54eed'  } ], 'goodsguid':'169494aa45f8fedf0145f99082290f1e', 'projectaccessorieList':[  {   'goodsname':'戴尔 软件 Microsoft？ Windows Server？ 2008（2012)标准版',   'projectaccessoryguid':'169494aa461a037801461dd900e64eea',   'projectgoodsguid':'169494aa461a037801461dd900d64ee9',   'qty':1,   'agreementprice':'5500',   'imgurl':'http://cg.hzft.gov.cn/gpos/upload/picture/2014/4/24/1398329497338_standardpath_factpath.jpg'  },  {   'goodsname':'戴尔 软件 SQL Server 2012 标准版,OEM, 5用户CAL, NFI, 含介质, 英文(包含 2008 R2 介质)，工厂预装',   'projectaccessoryguid':'169494aa461a037801461dd900e64eeb',   'projectgoodsguid':'169494aa461a037801461dd900d64ee9',   'qty':1,   'agreementprice':'23000',   'imgurl':'http://cg.hzft.gov.cn/gpos/upload/picture/2014/4/24/1398318277447_standardpath_factpath.jpg'  } ], 'projectgoodsguid':'169494aa461a037801461dd900d64ee9', 'priceguid':'169494aa45f8fedf0145f9cdb5e528a8', 'agreementprice':'12500', 'imgurl':'http://cg.hzft.gov.cn/gpos/upload/picture/2014/4/24/1398308383431_standardpath_factpath.jpg'}    ],'projecttype':2,'qty':'1','quotationcount':22,'projectname':'杭州市上城区清波街道办事处本级议价项目','projectcode':'HZZFCG-YJ-2014-19339','goodsclassname':'服务器'   }, {'endtime':'2014-08-20 14:00:00','projectguid':'8a80808a46fc3b8c0146fc69cd750028','projecttype':3,'qty':'2','orgcount':1,'quotationcount':3,'projectname':'HZZFCG-SJ-2014-00316','projectcode':'HZZFCG-SJ-2014-00316','goodsclassname':'台式电脑'   }  ] }";

}
